package com.jason.java.demo.spi;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.cby.example.Display;
import com.jason.java.demo.R;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * @description: SPIActivity
 * @author: ChenBaoYang
 * @createDate: 2022/3/11 2:13 下午
 */
public class SPIActivity extends AppCompatActivity {

    private TextView showTv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spi);
        showTv = findViewById(R.id.tv_show);
    }

    public void addModuleClick(View view) {

        ServiceLoader<Display> loader = ServiceLoader.load(Display.class);
        Iterator<Display> mIterator = loader.iterator();
        StringBuilder text = new StringBuilder();
        while (mIterator.hasNext()){
            text.append(mIterator.next().display());
            text.append("\n");
        }
        showTv.setText(text.toString());
    }
}
